home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-06-21 | 4.5 KB | 166 lines | [TEXT/CWIE] |
- /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
- *
- * The contents of this file are subject to the Netscape Public License
- * Version 1.0 (the "NPL"); you may not use this file except in
- * compliance with the NPL. You may obtain a copy of the NPL at
- * http://www.mozilla.org/NPL/
- *
- * Software distributed under the NPL is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
- * for the specific language governing rights and limitations under the
- * NPL.
- *
- * The Initial Developer of this code under the NPL is Netscape
- * Communications Corporation. Portions created by Netscape are
- * Copyright (C) 1998 Netscape Communications Corporation. All Rights
- * Reserved.
- */
- /*
- * mkgeturl.c
- * This file implements the main calling api for netlib.
- * Includes NET_InitNetlib, NET_Shutdown, NET_GetURL, and NET_ProcessNet
- *
- * Designed and originally implemented by Lou Montulli '94
- * Additions/Changes by Judson Valeski, Gagan Saksena 1997.
- */
-
-
-
- Note: Insert our code (which begins after the dashed line)
- after the following in the NET_GetURL() routine:
-
-
- /* the FE's were screwing up the use of force_reload
- * to get around a bug in the scroll to named anchor
- * code. So I gave them an enum NET_RESIZE_RELOAD
- * that they could use instead. NET_RESIZE_RELOAD
- * should be treated just like NET_DONT_RELOAD within
- * the netlib
- */
- if((URL_s->force_reload == NET_RESIZE_RELOAD) ||
- (URL_s->force_reload == NET_CACHE_ONLY_RELOAD))
- URL_s->force_reload = NET_DONT_RELOAD;
-
-
- ---------------
-
-
- /* rjc / shapiro hack begins here */
-
- #define ENABLE_BABEL 1
-
- #define BABEL_URL "http://babelfish.altavista.digital.com/cgi-bin/translate?"
- #define PIGLATIN_URL "http://voyager.cns.ohiou.edu/~jrantane/cgi/pig.cgi?text=%s&SUBMIT=CONVERT"
- #define BACKWARDS_URL "http://smeg.com/backwards/b2.cgi?url=%s"
-
- #define BABEL_NO_LANGUAGE 1
- #define BABEL_RANDOM_LANGUAGE 3
- #define PIGLATIN_LANGUAGE 4
- #define BACKWARDS_LANGUAGE 5
- #define BABEL_FIRST_ITEM 7
-
- #ifdef ENABLE_BABEL
-
- /* need to set: "doit" = "done", "urltext" = URL, and
- "lp" = one of the following:
- "en_fr" : English to French
- "en_de" : English to German
- "en_it" : English to Italian
- "en_pt" : English to Portuguese
- "en_es" : English to Spanish
- "fr_en" : French to English
- "de_en" : German to English
- "it_en" : Italian to English
- "es_en" : Spanish to English
- "pt_en" : Portuguese to English
- */
-
- if ((URL_s->method == URL_GET_METHOD) && (CLEAR_CACHE_BIT(output_format) == FO_PRESENT) &&
- ((type == HTTP_TYPE_URL) || (type == SECURE_HTTP_TYPE_URL)) )
- {
- int32 hackLanguage;
- char *munged, *postData, *escaped;
- char *babelMappings [] =
- {
- "en_fr", "en_de", "en_it", "en_pt", "en_es",
- "fr_en", "de_en", "it_en", "es_en", "pt_en",
- NULL
- };
-
- PREF_GetIntPref("hack.language", &hackLanguage);
- if (hackLanguage > BABEL_NO_LANGUAGE)
- {
- escaped = NET_Escape(URL_s->address, URL_XPALPHAS);
-
- if (hackLanguage == BABEL_RANDOM_LANGUAGE)
- {
- hackLanguage = BABEL_FIRST_ITEM + Random() % 10;
- }
- if (hackLanguage == PIGLATIN_LANGUAGE)
- {
- if ((munged = PR_smprintf(PIGLATIN_URL, escaped)) != NULL)
- {
- if (URL_s->address != NULL)
- {
- PR_Free(URL_s->address);
- }
- URL_s->address = munged;
- }
- }
- else if (hackLanguage == BACKWARDS_LANGUAGE)
- {
- if ((munged = PR_smprintf(BACKWARDS_URL, escaped)) != NULL)
- {
- if (URL_s->address != NULL)
- {
- PR_Free(URL_s->address);
- }
- URL_s->address = munged;
- }
- }
- else
- {
- munged = (char*) PR_Malloc(PL_strlen(BABEL_URL) + 1);
-
- if ((postData = PR_smprintf("doit=done&urltext=%s&lp=%s",
- ((escaped != NULL) ? escaped : URL_s->address),
- babelMappings[hackLanguage - BABEL_FIRST_ITEM])) != NULL)
- {
- /* mangle URL to point to babelfish */
- PL_strcpy(munged, BABEL_URL);
- if (URL_s->address != NULL)
- {
- PR_Free(URL_s->address);
- }
- URL_s->address = munged;
-
- /* babelfish wants a HTTP POST */
- URL_s->method = URL_POST_METHOD;
-
- /* set POST information for babelfish */
-
- if (URL_s->post_data != NULL)
- {
- PR_Free(URL_s->post_data);
- }
- URL_s->post_data = postData;
- URL_s->post_data_size = strlen(postData);
- URL_s->post_headers = PR_smprintf("Content-type: application/x-www-form-urlencoded\r\nContent-length: %lu\r\n",
- strlen(postData));
- }
- else
- {
- PR_Free(munged);
- }
- }
- if (escaped != NULL)
- {
- FREE(escaped);
- }
- }
- }
-
- /* rjc / shapiro hack ends here */
- #endif
-
-